package 校招笔试.美团笔试.美23826; /**
 * @author aodre , QQ : 480029069
 * @date 2023/8/26 8:41
 */

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().solve3();
    }


    public void solve5() {
        int n = sc.nextInt(), k = sc.nextInt();
        int nums[] = new int[n];
        int preSum[] = new int[n + 1];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
            preSum[i + 1] = preSum[i] + nums[i];
        }

//        int dp[] = new int[n];
//        dp[n - 1] = nums[n - 1] == k ? 1 : 0;
        int ans = -1;
        for (int i = 0;i < n;i++) {
            for(int j = i;j < n;j++){
                int len = (j + 1 - i);
                int sum = (preSum[j + 1] - preSum[i]);
                int x =sum / len;
                if(x * len  == sum && x ==  k){
                    ans = Math.max(ans,len);
                }
            }
        }
        System.out.println(ans);
    }


    public void solve3() {
        int n = sc.nextInt(), k = sc.nextInt();
        int nums[] = new int[n];
        PriorityQueue<Long> queue = new PriorityQueue<>((a, b) -> Long.compare(b, a));
        long sum = 0,ans = 0;
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();
            sum += nums[i];
            queue.add((long) nums[i]);
        }
        while (k-- > 0) {
            long l = queue.poll();
            long ll = queue.poll();
            long x = l * ll;
            sum = sum - (l + ll);
            queue.add(x);
            queue.add(1L);
            sum +=(x + 1);
            ans = Math.max(sum, ans);
        }
//        long ans = 0;
//        for (long num : queue) {
//            ans += num;
//        }
        System.out.println(ans % 1000000007);
    }

    public long recursion(int index, int k, int nums[], Integer dp[][]) {
        if (index == nums.length || k == 0) {
            return 0;
        }
        return 0;
    }


    public void solve2() {
        int n = sc.nextInt(), m = sc.nextInt();
        int ans[] = new int[m + 1];
        int bill[][] = new int[n][2];
        int map[][] = new int[n][]; // 账单 i 对应的

        for (int i = 0; i < n; i++) {
            bill[i][0] = sc.nextInt();
            bill[i][1] = sc.nextInt();
            map[i] = new int[bill[i][0] - 1];
            for (int j = 0; j < bill[i][0] - 1; j++) {
                map[i][j] = sc.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            int cost = (bill[i][1] + bill[i][0] - 1) / bill[i][0];
            for (int num : map[i]) {
                ans[num] += cost;
            }
        }
        for (int i = 1;i <= m; i++) {
            System.out.print(ans[i] + " ");
        }
    }


    public void solve1() {
        int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();
        int mod = 0, ans = 0;
        while (z > 0) {
            z -= x;
            if (mod % 3 == 0) {
                z -= y;
            }
            mod = (mod + 1) % 3;
            ans++;
        }
        System.out.println(ans);
    }

}
